<template>
	<view class="wrap">
		<view class="wrapList" v-if="list.length > 0">
		<scroll-view scroll-y style="height: 100%;width: 100%;" @scrolltolower="onreachBottom">
			<view class="list flex" v-for="(it, ins) in list" @click.stop="edit(it, 0)">
				<view class="img">{{ it.invoice_kind === 0 ? '个人' : '企业' }}</view>
				<view class="width-65 pl-15">{{ it.invoice_kind === 0 ? it.person_title : it.company_title }}</view>
				<view class="width-20 u-text-right " @click.stop="edit(it, 1)">
					<view class="edit">
						编辑
						<i-icon icon="icontubiao09" type="single" class="ml-10 " size="28rpx" color="#999"></i-icon>
					</view>
				</view>
			</view>
			
			</scroll-view>
			<u-loadmore :status="loadText[loadStatus]" />
		</view>
		<view class="" v-else><defaultImg :show="true" :msg='"暂无发票抬头信息,请先新增抬头！"'></defaultImg></view>
	</view>
</template>

<script>
import defaultImg from '@/components/defaultImg/defaultImg';
export default {
	data() {
		return {
			list: [],
			orderMsg:'',
			loadText: [
				'loadmore',
				'loading',
				'nomore'
			],
			loadStatus: 0,
			totalPage:0,
		};
	},
	components: {
		defaultImg
	},
	onNavigationBarButtonTap(e) {
		console.log(1111);
		uni.navigateTo({
			url: '/pages_order/addOrderInvoice/addOrderInvoice'
		});
	},
	onShow() {
		this.list=[]
		this.GetInvoiceTitleList();
	},
	onLoad(opt){
		this.orderMsg=JSON.parse(opt.data)
		console.log(opt)
		// this.GetInvoiceTitleList()
	},
	methods: {
		async GetInvoiceTitleList() {
			let data = {
				pageIndex: 1,
				pageSize: 10
			};
			try {
				const res = await this.$api.common.GetInvoiceTitleList(data);

				this.list= this.list.concat(res.data.list)
				this.totalPage=res.data.total
				if (Math.ceil(this.totalPage / 10) > this.pageIndex) {
				  this.loadStatus = 0
				} else {
				  this.loadStatus = 2
				}
				console.log(res);
			} catch (e) {
				//TODO handle the exception
			}
		},
		edit(id, index) {
			console.log(index);
			let data = encodeURIComponent(JSON.stringify(id));
			if (index === 0) {
				// 去往开票
				let allData={
					"tt":id,
					"order":this.orderMsg
				}
				uni.navigateTo({
					url: '/pages_order/orderInvoiceDetail/orderInvoiceDetail?id=' +encodeURIComponent(JSON.stringify(allData))
				});
			} else {
				// 去编辑抬头
				uni.navigateTo({
					url: '/pages_order/addOrderInvoice/addOrderInvoice?id=' + data
				});
			}
		},
		onreachBottom(){
		
		  if (Math.ceil(this.totalPage / 10) > this.pageIndex) {
		    this.loadStatus = 1
		    this.pageIndex++
		    this.GetInvoiceNeedList()
		  } else {
		    this.loadStatus = 2
		  }
		},
	}
};
</script>

<style scoped lang="scss">
.wrap {
	width: 100%;
	min-height: 100vh;
	background: #f6f6f6;
	padding-top: 14rpx;
	.wrapList{
		width: 100%;
		min-height: 100vh;
	}
	.list {
		width: 95%;
		margin: 10rpx auto;
		background: #ffffff;
		box-shadow: 0px 0px 10px 0px rgba(0, 0, 0, 0.1);
		border-radius: 10rpx;
		padding: 2%;
		view {
			height: 86rpx;
			line-height: 86rpx;
		}
		.img {
			width: 86rpx;
			height: 86rpx;
			line-height: 86rpx;
			text-align: center;
			font-size: 26rpx;
			font-weight: bold;
			background: linear-gradient(-90deg, #fdd421, #ffe23e);
			border-radius: 50%;
		}
		.edit {
			height: 48rpx;
			line-height: 48rpx;
			margin: 20rpx 0px;
			border-left: 2rpx solid #d2e0e6;
		}
	}
}
</style>
